(function(){

    let userALocation = document.getElementById("userA");
    let userBLocation = document.getElementById("userB");
    function Game(userA, userB){
        this.userA = userA;
        this.userB = userB;
    }
    
    /**
     * 初始化阶段
     */
    Game.prototype.init = function(){
        //创建用户A
        this.userA = new User("机器人");
        
        //用户B
        let name = prompt("请输入您的昵称，准备游戏");
        this.userB = new User(name);

        //用户A的位置
        this.userA.render(userALocation);
        this.userB.render(userBLocation); 
    }

    Game.prototype.start = function(){
        let step = new Step();

        //创建对方
        let stepA = step.createStep();
        //创建我方
        let stepB = step.createStep();

        stepA.render(document.getElementById("leftStep"));
        stepB.render(document.getElementById("rightStep"));

        setTimeout(()=>{
            let result = step.compare(stepA, stepB);
            if(result == "输"){
                // B输了
                this.userB.lose();
                this.userA.win();
            }else if(result == "赢"){
                // B赢了
                this.userB.win();
                this.userA.lose();
            }
            // 重新渲染
            this.userA.render(userALocation);
            this.userB.render(userBLocation);
            alert(result);
        },1000)
    }
    window.Game = Game;
})();